@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
    <!-- 配置文件 -->
    <script type="text/javascript" src="{{url('vendor/ueditor/ueditor.config.js')}}"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="{{url('vendor/ueditor/ueditor.all.js')}}"></script>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="javascript:void(0)">添加医院</a>
        </div>
        <!-- cur-position end -->

        <div class="list-wrap">
            <h2 class="head">
                <span class="span1">医院资料填写</span>
            </h2>

            <!-- list-text-box start -->
            <form id="addAdvertiserInfo">
                <div class="list-text-box">
                    <div class="fill-list">
                        <label class="fill-tit">医院名称：</label>
                        <div class="fill-cont">
                            <input class="fill-ipt" type="text" placeholder="请输入医院名称" name="name" id="name" value="@if($hospital){{$hospital->name}}@endif" /><span id="namere" class="required">*</span>
                        </div>
                    </div>
                    <div class="fill-list">
                        <label class="fill-tit">联系方式：</label>
                        <div class="fill-cont">
                            <input class="fill-ipt" type="text" placeholder="请输入医院联系电话" name="tel" id="tel" value="@if($hospital){{$hospital->telephone}}@endif" /><span id="namere" class="required">*</span>
                        </div>
                    </div>
                    <input type="hidden" id="hospital_id" name="hospital_id" value="@if($hospital){{$hospital->id}}@else 0 @endif" />
                    <div class="fill-list">
                        <label class="fill-tit">&nbsp;</label>
                        <div class="fill-cont">
                            <input class="fill-submit" type="button" id="btn_set" value="提交" />
                        </div>
                    </div>
                </div>
            </form>
            <!-- list-text-box end -->
        </div>
    </div>
    <!-- content end -->
    <script>
        jQuery(function($) {
            $("#btn_set").click(function () {
                var hospitalId = $("#hospital_id").val();
                var name       = $("#name").val();
                var tel        = $("#tel").val();
                $.ajax({
                    url:"{{route('Api.Admin.setHospital')}}",
                    type:"post",
                    dataType:"json",
                    data:{"id":hospitalId,"name":name,"telephone":tel},
                    success:function (obj) {
                        if(obj.level == "success"){
                            window.location.href="{{route('Admin.Index.hospitalList')}}";
                        }else {
                            alert(obj.message);
                        }
                    },
                    error:function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>
@endsection